package cn.kgm.article.server.exception;

import cn.kgm.core.exception.exceptionHandle.AbstractGlobalExceptionHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.DispatcherServlet;

import javax.servlet.Servlet;

/**
 * @kapi #技术改变自己#
 * @AUTHOR: ruoyi
 * @EMAIL: yolo.jk@qq.com
 * @DATE: 2023/6/14 0:54周三
 * @PACKAGE: cn.kgm.article.server.exception.GlobalExceptionHandler
 */
@Slf4j
@Configuration
@ConditionalOnClass({Servlet.class, DispatcherServlet.class})
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
@RestControllerAdvice(annotations = {RestController.class, Controller.class})
public class GlobalExceptionHandler extends AbstractGlobalExceptionHandler {

//    在这里写自定义异常
//    @ExceptionHandler(MallServiceException.class)
//    public R<?> mallServiceException(MallServiceException ex) {
//        LanguageExceptionService exception = exceptionFactory.getEnumsBySource(getSource());
//        log.warn("MkkOrderException: path={}, errorMsg={},exception={}", getPath(), ex.getMessage(), exception);
//        return R.result(250, null, StringUtils.isEmpty(ex.getMsg()) ? exception.getMsg(ex.getExceptionTypeEnums()) : ex.getMsg(), ex.getLocalizedMessage()).setPath(getPath());
//    }
}
